{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import xml.dom.minidom\n",
    "\n",
    "\n",
    "def read_xml(filename):\n",
    "    dom_tree = xml.dom.minidom.parse(filename)\n",
    "    annotation = dom_tree.documentElement\n",
    "    folder_name = annotation.getElementsByTagName('folder')[0].childNodes[0].data\n",
    "    image_filename = annotation.getElementsByTagName('filename')[0].childNodes[0].data\n",
    "    class_name = annotation.getElementsByTagName('object')[0].childNodes[1].childNodes[0].data\n",
    "    obj = annotation.getElementsByTagName('object')[0]\n",
    "    bndboxes = obj.getElementsByTagName('bndbox')[0]\n",
    "    xmin = bndboxes.getElementsByTagName('xmin')[0].childNodes[0].data\n",
    "    ymin = bndboxes.getElementsByTagName('ymin')[0].childNodes[0].data\n",
    "    xmax = bndboxes.getElementsByTagName('xmax')[0].childNodes[0].data\n",
    "    ymax = bndboxes.getElementsByTagName('ymax')[0].childNodes[0].data\n",
    "\n",
    "    return image_filename, class_name, [xmin, ymin, xmax, ymax]\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}